package com.spsoft.vatoutinv.service.vmsissuenegativeinvoices.imp;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spsoft.core.enums.ResponseEnum;
import com.spsoft.core.model.Result;
import com.spsoft.core.model.leqidmz.param.QueryRedConfirmDetailParam;
import com.spsoft.core.model.leqidmz.response.QueryRedConfirmDetailVO;
import com.spsoft.core.utils.BeanUtils;
import com.spsoft.core.utils.MoneyUtils;
import com.spsoft.core.utils.SecurityUtils;
import com.spsoft.core.utils.StringUtil;
import com.spsoft.einvoicetodmz.service.DmzApiClientService;
import com.spsoft.system.model.vo.InvoiceItemVo;
import com.spsoft.system.model.vo.InvoiceVo;
import com.spsoft.vatoutinv.constants.CommonConstant;
import com.spsoft.vatoutinv.entity.vmsfullbswjmanager.VmsFullBswjManager;
import com.spsoft.vatoutinv.entity.vmsfulloutinvoice.*;
import com.spsoft.vatoutinv.entity.vmshzqrdmanage.VmsLeqiHzqrd;
import com.spsoft.vatoutinv.entity.vmshzqrdmanage.VmsLeqiHzqrdItem;
import com.spsoft.vatoutinv.enums.*;
import com.spsoft.vatoutinv.model.dto.vmsfulloutinvoice.VmsFullOutInvoiceInfoDto;
import com.spsoft.vatoutinv.model.dto.vmsissuenegativeinvoices.RedConfirmationFormDto;
import com.spsoft.vatoutinv.model.vo.vmsissuenegativeincoices.RedConfirmationFormVo;
import com.spsoft.vatoutinv.model.vo.vmsissuenegativeincoices.manual.VmsApprovalHzqrdManualVo;
import com.spsoft.vatoutinv.model.vo.vmsissuenegativeincoices.manual.VmsManualBaseVo;
import com.spsoft.vatoutinv.model.vo.vmsissuenegativeincoices.manual.VmsManualDetailVo;
import com.spsoft.vatoutinv.service.commoninvoice.CommonInvoiceService;
import com.spsoft.vatoutinv.service.issueinvoice.IssueInvoiceService;
import com.spsoft.vatoutinv.service.vmsenterpriseinfo.VmsEnterpriseInfoService;
import com.spsoft.vatoutinv.service.vmsenterpriseinforisk.VmsEnterpriseInfoRiskService;
import com.spsoft.vatoutinv.service.vmsfullbswjmanager.VmsFullBswjManagerService;
import com.spsoft.vatoutinv.service.vmsfulloutinvoice.*;
import com.spsoft.vatoutinv.service.vmshzqrdmanage.VmsLeqiHzqrdItemService;
import com.spsoft.vatoutinv.service.vmshzqrdmanage.VmsLeqiHzqrdService;
import com.spsoft.vatoutinv.service.vmsissuenegativeinvoices.VmsIssueNegativeInvoicesService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author wangy
 * @date 2024/1/22 9:37
 */
@Slf4j
@Service
@RequiredArgsConstructor
@SuppressWarnings("unchecked")
public class VmsIssueNegativeInvoicesServiceImpl implements VmsIssueNegativeInvoicesService {

    private final VmsLeqiHzqrdService vmsLeqiHzqrdService;

    private final VmsLeqiHzqrdItemService vmsLeqiHzqrdItemService;

    private final VmsFullOutInvoiceDetailsService fullOutInvoiceDetailsService;

    private final IssueInvoiceService issueInvoiceService;

    private final VmsEnterpriseInfoService vmsEnterpriseInfoService;

    private final VmsEnterpriseInfoRiskService vmsEnterpriseInfoRiskService;

    private final VmsFullOutInvoiceItemsExpService vmsFullOutInvoiceItemsExpService;

    private final VmsFullOutInvoiceItemsAddService vmsFullOutInvoiceItemsAddService;

    private final VmsFullOutInvoiceTdywService vmsFullOutInvoiceTdywService;

    private final VmsFullOutInvoiceTdywItemService vmsFullOutInvoiceTdywItemService;

    private final VmsFullBswjManagerService vmsFullBswjManagerService;

    private final CommonInvoiceService commonInvoiceService;

    private final DmzApiClientService dmzApiClientService;

    /**
     * 校验纳税人基本信息、风险信息
     */
    public void checkStatus(String type) {
        String deptCode = SecurityUtils.getDeptCode();
        // 开票方纳税人状态
        vmsEnterpriseInfoService.checkStatus(deptCode, type);
        // 风险纳税人校验
        vmsEnterpriseInfoRiskService.checkStatus(deptCode, type);
    }

    /**
     * 在已开发票中获取负数发票
     */
    @Override
    public Result<IPage<RedConfirmationFormVo>> redConfirmationForm(RedConfirmationFormDto dto) {
        Integer pageNo = dto.getPageNo();
        Integer pageSize = dto.getPageSize();
        LambdaQueryWrapper<VmsFullOutInvoiceDetails> lq = new LambdaQueryWrapper<VmsFullOutInvoiceDetails>()
                .eq(VmsFullOutInvoiceDetails::getQydjid, SecurityUtils.getDeptCode())
                .eq(VmsFullOutInvoiceDetails::getLzfpbz, CommonEnum.INVOICE_RED.getKey())
                .eq(VmsFullOutInvoiceDetails::getFpzt, CommonEnum.INVOICE_STATUS_0.getKey())
                .orderByDesc(VmsFullOutInvoiceDetails::getKprq, VmsFullOutInvoiceDetails::getFoidid);
        IPage<RedConfirmationFormVo> page = fullOutInvoiceDetailsService.page(new Page<>(pageNo, pageSize), lq)
                .convert(item -> {
                    RedConfirmationFormVo vo = new RedConfirmationFormVo();
                    BeanUtils.copyBeanProp(vo, item);
                    vo.setHzxxqrdbh(item.getHzqrxxdbh());
                    return vo;
                });
        return Result.OK(page);
    }

    /**
     * 根据红字确认单获取发票信息
     *
     * @param hzfpxxqrdbh 红字确认单编号
     * @return 发票信息 发票明细信息
     */
    @Override
    public Result<VmsApprovalHzqrdManualVo> getInfoByRedNo(String hzfpxxqrdbh) {
        VmsApprovalHzqrdManualVo vo = new VmsApprovalHzqrdManualVo();
        VmsManualBaseVo vmsManualBaseVo = new VmsManualBaseVo();
        List<VmsManualDetailVo> vmsManualDetailVoList = new ArrayList<>();
        VmsLeqiHzqrd one = vmsLeqiHzqrdService.getOne(new LambdaQueryWrapper<VmsLeqiHzqrd>()
                .eq(VmsLeqiHzqrd::getHzfpxxqrdbh, hzfpxxqrdbh)
                .eq(VmsLeqiHzqrd::getQydjid, SecurityUtils.getDeptCode())
        );
        if (ObjectUtil.isEmpty(one)) {
            return Result.ERROR(ResponseEnum.NO_RED_CONFIRMATION_FORM_FOUND);
        }
        // 红字确认单的销方税号需要与当前机构税号一致
        String nsrsbh = vmsEnterpriseInfoService.getNsrsbh();
        if (!one.getXsfnsrsbh().equals(nsrsbh)) {
            return Result.ERROR(ResponseEnum.HZQRD_XSFSBH_ERROR);
        }
        // 后续以接口返回的红字确认单状态为准
        if (StrUtil.equalsAny(one.getHzqrxxztdm(), CommonEnum.HZQRD_STATUS_02.getKey(), CommonEnum.HZQRD_STATUS_03.getKey())) {
            return Result.ERROR(ResponseEnum.HZQRD_QR_STATUS_ERROR);
        }
        if (StrUtil.equalsAny(one.getHzqrxxztdm(), CommonEnum.HZQRD_STATUS_05.getKey(), CommonEnum.HZQRD_STATUS_06.getKey(),
                CommonEnum.HZQRD_STATUS_07.getKey(), CommonEnum.HZQRD_STATUS_08.getKey(),
                CommonEnum.HZQRD_STATUS_09.getKey(), CommonEnum.HZQRD_STATUS_10.getKey())) {
            return Result.ERROR(ResponseEnum.HZQRD_STATUS_ERROR);
        }
        // 已开具红字发票标志
        if (CommonEnum.YKJHZFP_YES.getKey().equals(one.getYkjhzfpbz())) {
            return Result.ERROR(ResponseEnum.HZQRD_USED_ERROR);
        }

        BeanUtils.copyBeanProp(vmsManualBaseVo, one);
        List<VmsLeqiHzqrdItem> list = vmsLeqiHzqrdItemService.list(new LambdaQueryWrapper<VmsLeqiHzqrdItem>()
                .eq(VmsLeqiHzqrdItem::getHzqrdId, one.getId())
                .orderByAsc(VmsLeqiHzqrdItem::getXh)
        );
        // 不含税金额合计
        BigDecimal je = new BigDecimal(0);
        if (!list.isEmpty()) {
            for (VmsLeqiHzqrdItem vmsLeqiHzqrdItem : list) {
                VmsManualDetailVo vmsManualDetailVo = new VmsManualDetailVo();
                BeanUtils.copyBeanProp(vmsManualDetailVo, vmsLeqiHzqrdItem);
                vmsManualDetailVoList.add(vmsManualDetailVo);
                je = je.add(vmsLeqiHzqrdItem.getJe()).add(vmsLeqiHzqrdItem.getSe()).setScale(2, RoundingMode.HALF_UP);
            }
        }
        vmsManualBaseVo.setKpr(SecurityUtils.getUsername());
        vmsManualBaseVo.setJshjText(MoneyUtils.toChinese(StringUtil.toString(je)));
        vmsManualBaseVo.setJshj(StringUtil.toString(je));
        if (StringUtils.isNotBlank(one.getLzfpdm())) {
            // 被红冲蓝字发票代码：%s 蓝字发票号码：%s 红字发票信息确认单编号：%s
            vmsManualBaseVo.setBz(String.format(CommonConstant.RED_BZ_SK, one.getLzfpdm(), one.getLzfphm(), hzfpxxqrdbh));
        } else {
            // 被红冲蓝字数电票号码：%s 红字发票信息确认单编号：%s
            vmsManualBaseVo.setBz(String.format(CommonConstant.RED_BZ_SD, one.getLzfphm(), hzfpxxqrdbh));
        }
        vo.setVmsManualBase(vmsManualBaseVo);
        vo.setVmsManualDetail(vmsManualDetailVoList);
        return Result.OK(vo);
    }

    @Override
    public Result<Object> invoice(String hzfpxxqrdbh, String bz) {
        // 校验纳税人基本信息、风险信息
        checkStatus("2");
        /**
         * 1. 校验选择的红字确认单状态，如状态为“作废”（包括：05：作废（销方录入购方否认） 06：作废（购方录入销方否认）
         *    07：作废（超72小时未确认） 08：（发起方撤销） 09：作废（确认后撤销） 10 作废（异常凭证）），
         *    则不允许发起“开票”，提示：“红字确认单状态异常！不得开票，请核实后重新发起申请！”
         * 2. 根据选择的“红字确认单编码”校验开票信息与红字确认单明细信息对应字段的信息是否一致，如明细信息不一致，
         *    则提示“红字确认单明细不符！不得开票，请核实后重新发起申请！
         */
        // 根据红字确认单编号 查询信息
        VmsLeqiHzqrd leqiHzqrd = vmsLeqiHzqrdService.getOne(new LambdaQueryWrapper<VmsLeqiHzqrd>()
                .eq(VmsLeqiHzqrd::getHzfpxxqrdbh, hzfpxxqrdbh)
                .eq(VmsLeqiHzqrd::getQydjid, SecurityUtils.getDeptCode())
        );
        if (ObjectUtil.isEmpty(leqiHzqrd)) {
            return Result.ERROR(ResponseEnum.NO_RED_CONFIRMATION_FORM_FOUND);
        }
        // 红字确认单的销方税号需要与当前机构税号一致
        String nsrsbh = vmsEnterpriseInfoService.getNsrsbh();
        if (!leqiHzqrd.getXsfnsrsbh().equals(nsrsbh)) {
            return Result.ERROR(ResponseEnum.HZQRD_XSFSBH_ERROR);
        }

        // 调用乐企接口查询数电红字确认单明细信息
        QueryRedConfirmDetailParam itemParam = new QueryRedConfirmDetailParam();
        itemParam.setXsfnsrsbh(leqiHzqrd.getXsfnsrsbh());
        itemParam.setUuid(leqiHzqrd.getUuid());
        itemParam.setCreateUser(SecurityUtils.getUserCode());
        itemParam.setDeptCode(SecurityUtils.getDeptCode());
        Result<QueryRedConfirmDetailVO> itemResult = dmzApiClientService.queryRedConfirmDetail(itemParam, null);
        if (!ResponseEnum.SUCCESS.getCode().equals(itemResult.getCode())) {
            return Result.ERRORT(itemResult.getCode(), itemResult.getMessage());
        }
        QueryRedConfirmDetailVO itemResultData = itemResult.getData();
        // 将乐企返回的红字确认单信息同步到本地
        vmsLeqiHzqrdService.syncSingleLeqiHzqrd(itemResultData, SecurityUtils.getTokenUser());

        // 以乐企返回的红字确认单状态为准
        if (StrUtil.equalsAny(itemResultData.getHzqrxxztDm(), CommonEnum.HZQRD_STATUS_02.getKey(), CommonEnum.HZQRD_STATUS_03.getKey())) {
            return Result.ERROR(ResponseEnum.HZQRD_QR_STATUS_ERROR);
        }
        if (StrUtil.equalsAny(itemResultData.getHzqrxxztDm(), CommonEnum.HZQRD_STATUS_05.getKey(), CommonEnum.HZQRD_STATUS_06.getKey(),
                CommonEnum.HZQRD_STATUS_07.getKey(), CommonEnum.HZQRD_STATUS_08.getKey(),
                CommonEnum.HZQRD_STATUS_09.getKey(), CommonEnum.HZQRD_STATUS_10.getKey())) {
            return Result.ERROR(ResponseEnum.HZQRD_STATUS_ERROR);
        }
        // 以乐企返回的已开具红字发票标志为准
        if (CommonEnum.YKJHZFP_YES.getKey().equals(itemResultData.getYkjhzfpbz())) {
            return Result.ERROR(ResponseEnum.HZQRD_USED_ERROR);
        }

        List<VmsLeqiHzqrdItem> leqiHzqrdItemList = vmsLeqiHzqrdItemService.list(new LambdaQueryWrapper<VmsLeqiHzqrdItem>()
                .eq(VmsLeqiHzqrdItem::getHzqrdId, leqiHzqrd.getId())
                .orderByAsc(VmsLeqiHzqrdItem::getXh)
        );
        if (CollectionUtil.isEmpty(leqiHzqrdItemList)) {
            return Result.ERROR(ResponseEnum.NO_RED_CONFIRMATION_FORM_ITEM_FOUND);
        }

        // 查询蓝字发票信息（可能是进项票、税控票、数电票）
        InvoiceVo lzfp = commonInvoiceService.queryInvoice(leqiHzqrd.getLzfpdm(), leqiHzqrd.getLzfphm(), true);
        if (lzfp == null) {
            return Result.ERROR(ResponseEnum.NO_BLUE_INVOICE_FOUND);
        }
        List<InvoiceItemVo> invoiceItemVoList = lzfp.getInvoiceItemVoList();

        HashMap<Long, InvoiceItemVo> itemMap = new HashMap<>();
        for (InvoiceItemVo invoiceItems : invoiceItemVoList) {
            itemMap.put(invoiceItems.getMxxh(), invoiceItems);
        }

        // 构造成发票信息 传入公共开票接口
        List<VmsFullOutInvoiceInfoDto> dto = new ArrayList<>();
        VmsFullOutInvoiceInfoDto vmsFullOutInvoiceInfoDto = new VmsFullOutInvoiceInfoDto();
        // 发票基本信息
        VmsFullOutInvoiceDetails vmsFullOutInvoiceDetails = new VmsFullOutInvoiceDetails();

        // 蓝字发票信息回填
        vmsFullOutInvoiceDetails.setLzfpbz(LzfpbzEnum.RED.getKey());
        vmsFullOutInvoiceDetails.setDhlx(lzfp.getDhlx());
        vmsFullOutInvoiceDetails.setDh(lzfp.getDh());
        vmsFullOutInvoiceDetails.setTdys(lzfp.getTdys());
        vmsFullOutInvoiceDetails.setCezslxdm(lzfp.getCezslxdm());
        vmsFullOutInvoiceDetails.setZsfs(lzfp.getZsfs());
        if (StringUtils.isNotBlank(lzfp.getSfbdc())) {
            vmsFullOutInvoiceDetails.setSfbdc(lzfp.getSfbdc());
        } else {
            vmsFullOutInvoiceDetails.setSfbdc(CommonEnum.SFBDC_NO.getKey());
        }
        vmsFullOutInvoiceDetails.setSjkly(lzfp.getSjkly());

        // 红字确认单信息填充
        vmsFullOutInvoiceDetails.setFppz(leqiHzqrd.getLzfppzdm());
        vmsFullOutInvoiceDetails.setGmfmc(leqiHzqrd.getGmfmc());
        vmsFullOutInvoiceDetails.setGmfnsrsbh(leqiHzqrd.getGmfnsrsbh());
        vmsFullOutInvoiceDetails.setXsfmc(leqiHzqrd.getXsfmc());
        vmsFullOutInvoiceDetails.setXsfnsrsbh(leqiHzqrd.getXsfnsrsbh());
        vmsFullOutInvoiceDetails.setHjje(leqiHzqrd.getHzcxje());
        vmsFullOutInvoiceDetails.setHjse(leqiHzqrd.getHzcxse());
        String dylzfphm = StringUtil.toString(leqiHzqrd.getLzfpdm()) + StringUtil.toString(leqiHzqrd.getLzfphm());
        vmsFullOutInvoiceDetails.setDylzfphm(dylzfphm);
        vmsFullOutInvoiceDetails.setHzqrxxdbh(hzfpxxqrdbh);
        vmsFullOutInvoiceDetails.setHzqrduuid(leqiHzqrd.getUuid());
        vmsFullOutInvoiceDetails.setKprq(new Date());
        vmsFullOutInvoiceDetails.setPpzt(CommonEnum.MATCHING_STATUS_0.getKey());
        vmsFullOutInvoiceDetails.setSczt(CommonEnum.INVOICE_UPLOAD_STATUS_0.getKey());
        vmsFullOutInvoiceDetails.setFpzt(FpztEnum.NORMAL.getKey());
        vmsFullOutInvoiceDetails.setQydjid(SecurityUtils.getDeptCode());
        vmsFullOutInvoiceDetails.setZfchrq(new Date());
        vmsFullOutInvoiceDetails.setZfchyy(leqiHzqrd.getChyydm());
        vmsFullOutInvoiceDetails.setSjly(CommonEnum.DATA_SOURCE_1.getKey());
        vmsFullOutInvoiceDetails.setKpzt(KpztEnum._0.getKey());
        vmsFullOutInvoiceDetails.setJshj(vmsFullOutInvoiceDetails.getHjje().add(vmsFullOutInvoiceDetails.getHjse()));
        vmsFullOutInvoiceDetails.setDelFlag(CommonEnum.DEL_STATUS_0.getKey());
        vmsFullOutInvoiceDetails.setCreatTime(new Date());
        vmsFullOutInvoiceDetails.setCreatBy(SecurityUtils.getUserCode());
        vmsFullOutInvoiceDetails.setUpdateTime(new Date());
        vmsFullOutInvoiceDetails.setUpdateBy(SecurityUtils.getUserCode());
        vmsFullOutInvoiceDetails.setKpr(SecurityUtils.getUsername());
        vmsFullOutInvoiceDetails.setJems(CommonEnum.AMOUNT_MODE_01.getKey());
        vmsFullOutInvoiceDetails.setBz(bz);
        vmsFullOutInvoiceInfoDto.setVmsFullOutInvoiceDetails(vmsFullOutInvoiceDetails);

        if (CollectionUtil.isNotEmpty(leqiHzqrdItemList)) {
            // 发票明细信息
            List<VmsFullOutInvoiceItems> vmsFullOutInvoiceItemsList = leqiHzqrdItemList.stream().map(item -> {
                VmsFullOutInvoiceItems invoiceItems = new VmsFullOutInvoiceItems();
                invoiceItems.setMxxh(item.getXh());
                invoiceItems.setDylzfpmxxh(item.getLzmxxh());
                invoiceItems.setXmmc(item.getXmmc());
                invoiceItems.setGgxh(item.getGgxh());
                invoiceItems.setDw(item.getDw());
                invoiceItems.setSl(item.getFpspsl());
                invoiceItems.setDj(item.getFpspdj());
                invoiceItems.setJe(item.getJe());
                invoiceItems.setSlv(item.getSl1());
                invoiceItems.setSe(item.getSe());
                invoiceItems.setSphfwssflhbbm(item.getSphfwssflhbbm());
                invoiceItems.setFphxz(CommonEnum.FPHXZ_00.getKey());
                // 产品编码、计税方法、征税项目、扣除额、优惠政策标识
                InvoiceItemVo invoiceItems1 = itemMap.get(item.getLzmxxh());
                invoiceItems.setCpbm(invoiceItems1.getCpbm());
                invoiceItems.setJsff(invoiceItems1.getJsff());
                invoiceItems.setZsxm(invoiceItems1.getZsxm());
                if (ObjectUtil.isNotEmpty(invoiceItems1.getKce())) {
                    invoiceItems.setKce(invoiceItems1.getKce().negate());
                }
                invoiceItems.setYhzcbs(invoiceItems1.getYhzcbs());
                invoiceItems.setCreatTime(new Date());
                invoiceItems.setCreatBy(SecurityUtils.getUsername());

                return invoiceItems;
            }).collect(Collectors.toList());
            vmsFullOutInvoiceInfoDto.setVmsFullOutInvoiceItemsList(vmsFullOutInvoiceItemsList);
        }

        // 数电发票组装入参
        if (CommonEnum.SJKLY_SD.getKey().equals(lzfp.getSjkly())) {
            // 非必填扩展信息
            VmsFullOutInvoiceItemsExp exp = vmsFullOutInvoiceItemsExpService.getInvoiceExpInfoByFoidid(lzfp.getId());
            if (ObjectUtil.isNotEmpty(exp)) {
                vmsFullOutInvoiceInfoDto.setVmsFullOutInvoiceItemsExp(exp);
            }

            // 附加要素信息
            List<VmsFullOutInvoiceItemsAdd> vmsFullOutInvoiceItemsAdd = vmsFullOutInvoiceItemsAddService.getInvoiceAddInfoByFoidid(lzfp.getId());
            if (CollectionUtil.isNotEmpty(vmsFullOutInvoiceItemsAdd)) {
                vmsFullOutInvoiceInfoDto.setVmsFullOutInvoiceItemsAddList(vmsFullOutInvoiceItemsAdd);
            }

            // 特定业务信息
            if (StrUtil.equalsAny(lzfp.getTdys(), TdysEnum.TDYS_05.getCode(), TdysEnum.TDYS_06.getCode(), TdysEnum.TDYS_09.getCode())) {
                List<VmsFullOutInvoiceTdyw> tdywList = vmsFullOutInvoiceTdywService.getInfoByFoidid(lzfp.getId());
                if (CollectionUtil.isNotEmpty(tdywList)) {
                    VmsFullOutInvoiceTdyw invoiceTdyw = tdywList.get(0);
                    // 不动产销售共同购买方特殊处理
                    if (TdysEnum.TDYS_05.getCode().equals(lzfp.getTdys())
                            && CommonConstant.STR_Y.equals(invoiceTdyw.getDfgtgmbz())) {
                        List<VmsFullOutInvoiceTdywItem> tdywItemList = vmsFullOutInvoiceTdywItemService.getInvoiceTdywItemByTdywId(invoiceTdyw.getTdywId());
                        invoiceTdyw.setTdywItemList(tdywItemList);
                    }
                    vmsFullOutInvoiceInfoDto.setVmsFullOutInvoiceTdywList(tdywList);
                }
            }
        } else {
            // 进项票、税控票补充必填字段
            VmsFullOutInvoiceItemsExp invoiceItemsExp = new VmsFullOutInvoiceItemsExp();
            VmsFullBswjManager bswjManager = vmsFullBswjManagerService.getOneByWhjg(SecurityUtils.getDeptCode());
            invoiceItemsExp.setQydm(bswjManager.getQydm());

            vmsFullOutInvoiceInfoDto.setVmsFullOutInvoiceItemsExp(invoiceItemsExp);
        }

        // 构造开票接口入参
        dto.add(vmsFullOutInvoiceInfoDto);
        Result<Object> result = issueInvoiceService.issueInvoice(dto, SecurityUtils.getTokenUser());
        if (ResponseEnum.SUCCESS.getCode().equals(result.getCode())) {
            return Result.OK(ResponseEnum.SUCCESSFULLY_ISSUED_NEGATIVE_INVOICE.getMsg());
        } else {
            return result;
        }
    }

    @Override
    public Result<Object> checkStatus() {
        checkStatus("2");
        return Result.OK();
    }
}